#include <iostream>
#include <cstdio>
typedef long long ll;
using namespace std;
int main() {
    int n, p;
    cin>>n>>p;
    ll res=1;
    for (int i=1; i<=n; i++) {
        res=res*i%p;
    }
    cout<<res<<endl;
    return 0;
}
